import json

from django.conf import settings
from .base import Base


class UploadLog(Base):
    def __init__(self, data):
        super(UploadLog, self).__init__(data)
        self.wait_num = 5*60

    def struct_msg(self):
        date, hour = self.mission.description.split(",")
        url = "".join([settings.UPLOADURL, "?file_path=", self.mission.file_path])
        msg = {"TID": self.tid,
               "SID": self.sid,
               "TYPE": 0,
               "PATH": url,
               "DATE": date,
               "HOUR": hour}
        msg = json.dumps(msg)
        return msg

    def struct_pub_topic(self):
        notify = "transfer"
        gid = "".join(["/", self.gateway_id, "/"])
        func = "upload"
        topic = "".join([notify, gid, func])
        return topic

    def struct_sub_topic(self):
        notify = "transfered"
        gid = "".join(["/", self.gateway_id, "/"])
        func = "upload"
        topic = "".join([notify, gid, func])
        return topic
